package com.ruoyi.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.config.SearchRequestData;
import com.ruoyi.entity.Article;
import com.ruoyi.netty.ElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author hlf
 * @createTime 2025/2/10 16:26
 * @description
 */
@RestController
@RequestMapping("/els/testElastic")
public class ElasticSearchController  extends BaseController {

    @Autowired
    private ElasticSearchService elasticSearchService;

    /**
     * @description 返回es分页高亮
     * @author hlf
     * @date 2025/2/28 14:59
     **/
    @PostMapping("/highlight")
    @Anonymous
    public List<Article> search(@RequestBody SearchRequestData request) {
        return elasticSearchService.searchWithHighlight(request);
    }

    /**
     * @description 适配前端页面的接口，返回es分页高亮
     * @author hlf
     * @date 2025/2/28 15:00
     **/
    @PostMapping("/highlightList")
    @Anonymous
    public TableDataInfo highlightList(@RequestBody SearchRequestData request) throws IOException {
        return elasticSearchService.highlightList(request);
    }
    /**
     * @description 搜索补全
     * @author hlf
     * @date 2025/2/28 15:00
     **/
    @PostMapping("/getArticleSuggestionText")
    @Anonymous
    public AjaxResult getArticleSuggestionText(@RequestBody SearchRequestData request) {
        return AjaxResult.success(elasticSearchService.getArticleSuggestionText(request));
    }

    /**
     * @description 查看得分
     * @author hlf
     * @date 2025/2/11 14:12
     **/
    @PostMapping("/score")
    @Anonymous
    public List<Article> searchScore(@RequestBody SearchRequestData request) {
        return elasticSearchService.searchScore(request);
    }





}
